﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenWeb.Dal.Interfaces;
using System.Data.Objects;
using System.Data.Entity;

namespace OpenWeb.Dal.Infrastructure
{

  public class PocoRepositoryContext : IRepositoryContext
    {
      private const string OBJECT_CONTEXT_KEY = "OpenWeb.Dal.Models.GoldCrmDbEntities";// riferimento a Poco context
      public IDbSet<T> GetObjectSet<T>() 
            where T : class
        {
            return PocoContextManager.GetObjectContext(OBJECT_CONTEXT_KEY).Set<T>();
          
        }


        /// <summary>
        /// Returns the active object context
        /// </summary>
      public DbContext ObjectContext
        {
            get
            {
                return PocoContextManager.GetObjectContext(OBJECT_CONTEXT_KEY);
            }
        }

        public int SaveChanges()
        {
            return this.ObjectContext.SaveChanges();
        }

        public void Terminate()
        {
            PocoContextManager.SetRepositoryContext(null, OBJECT_CONTEXT_KEY);
        }


        IObjectSet<T> IRepositoryContext.GetObjectSet<T>()
        {
          throw new NotImplementedException();
        }

        ObjectContext IRepositoryContext.ObjectContext
        {
          get { throw new NotImplementedException(); }
        }


        public IDbSet<T> GetDbSet<T>() where T : class
        {
          throw new NotImplementedException();
        }

        public DbContext DbContext
        {
          get { throw new NotImplementedException(); }
        }
    }
}
